Searching & Sorting

LPVOID BSearch(
    LPCVOID lpvKey,
    LPCVOID lpvBase,
    SIZE_T nNum,
    SIZE_T nWidth,
    const TCHAR * ptcCompareFunc)


Returns a pointer to an occurrence of lpvKey in the array pointed to by lpvBase. If lpvKey is not found, the function returns NULL. If the array is not in ascending sort order or contains duplicate records with identical keys, the result is unpredictable.
The BSearch() function performs a binary search of a sorted array of nNum elements, each of nWidth bytes in size. The lpvBase value is a pointer to the base of the array to be searched, and lpvKey is the value being sought. The ptcCompareFunc parameter is a string indicating a user-supplied script routine that compares two array elements and returns a value specifying their relationship. BSearch() calls the ptcCompareFunc routine one or more times during the search, passing pointers to two array elements on each call. The compare routine compares the elements, then returns one of the following values:
    Return < 0: lpvElem1 less than lpvElem2
    Return == 0: lpvElem1 equivalent to lpvElem2
    Return > 0: lpvElem1 greater than lpvElem2


BOOL QSort(
    LPCVOID lpvBase,
    SIZE_T nNum,
    SIZE_T nWidth,
    const TCHAR * ptcCompareFunc)


Implements a quick-sort algorithm to sort an array of nNum elements, each of nWidth bytes. The argument lpvBase is a pointer to the base of the array to be sorted.
QSort() overwrites this array with the sorted elements. The argument ptcCompareFunc is a string indicating a user-supplied script routine that compares two array elements and returns a value specifying their relationship. QSort() calls the ptcCompareFunc routine one or more times during the sort, passing pointers to two array elements on each call:
    pcCompareFunc( (LPVOID) lpvElem1, (LPVOID) lpvElem2 );

The routine must compare the elements, then return one of the following values:
    Return < 0: lpvElem1 less than lpvElem2
    Return == 0: lpvElem1 equivalent to lpvElem2
    Return > 0: lpvElem1 greater than lpvElem2

The array is sorted in increasing order, as defined by the comparison function. To sort an array in decreasing order, reverse the sense of “greater than” and “less than” in the comparison function.
Returns FALSE if the sort fails due to an invalid ptcCompareFunc parameter.


BOOL RegExMatch(
    const CHAR * pcRegEx,
    const CHAR * pcCheck,
    INT * piLength)


Determines if pcCheck is a match for the regular-expression string pcRegEx. If a match is found, piLength will be set to the match length.

Example of usage:
    RegExMatch("[0-9+]","780 Miles", &iRet )
        The function will return TRUE and iRet will be set to 3.


Copyright © 2006 Shawn (L. Spiro) Wilcoxen